
#include "NodeAnd.h"
#include <utility>

using namespace npInterpreter;
using namespace std;


NodeAnd::NodeAnd() : Node() // class inheritance
{
    //To initialize data member;
    this->left = nullptr;
    this->right = nullptr;
}

NodeAnd::~NodeAnd()
{
    //To delete dynamic data member
    delete this->left;
    delete this->right;
}

NodeAnd::NodeAnd(const NodeAnd& cpy) : Node(cpy) // class inheritance
{
    //To copy data member
    this->left = cpy.left->clone();
    this->right = cpy.right->clone();
}

NodeAnd& NodeAnd::operator=(const NodeAnd& asn)
{
    if (this == &asn)
    {
        return *this;
    }
    else
    {
        //To invoke base class operator=
        Node::operator=(asn);
        //To assign data member, note to delete dynamic member if exists.
        delete this->left;
        delete this->right;
        this->left = asn.left->clone();
        this->right = asn.right->clone();

        return *this;
    }
}

NodeAnd::NodeAnd(NodeAnd&& mov) noexcept : Node(move(mov)) // class inheritance
{
    //to move data
    this->left = mov.left;
    this->right = mov.right;
    mov.left = nullptr;
    mov.right = nullptr;
}

NodeAnd& NodeAnd::operator=(NodeAnd&& mva) noexcept
{
    if (this == &mva)
    {
        return *this;
    }
    else
    {
        //to inform base class to move data
        Node::operator=(move(mva));
        // to move data
        delete this->left;
        delete this->right;
        this->left = mva.left;
        this->right = mva.right;
        mva.left = nullptr;
        mva.right = nullptr;

        return *this;
    }
}

NodeAnd* NodeAnd::clone() const
{
    //return new
    return new NodeAnd(*this);
}

//other constructors
NodeAnd::NodeAnd(Node* left, Node* right) : Node()
{
    this->left = left;
    this->right = right;
}

//public methods
string NodeAnd::interpret() throw()
{
    return this->left->interpret() + "再" + this->right->interpret();
}

//protected methods

//private methods

//others
